package com.modelscope.ai.controller;

import com.modelscope.ai.domain.entity.R;
import com.modelscope.ai.domain.vo.ExamVo;
import com.modelscope.ai.service.ExamService;
import com.modelscope.ai.utils.RequestHolder;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequiredArgsConstructor
@Slf4j
@Validated
@RestController
@RequestMapping("/exam")
@Tag(name = "exam", description = "获取考试成绩")
public class ExamController {


    final ExamService examService;

    // 获取考试成绩
    // 搜索成绩模块
    @GetMapping("submit")
    public R<String> submit(Long articleId) {
        Long uid = RequestHolder.get().getUid();
        examService.submit(uid, articleId);
        return R.ok("考试成绩提交成功");
    }

    // 接下来是访问

    @GetMapping("list")
    public R<List<ExamVo>> queryExamAll(){
        Long uid = RequestHolder.get().getUid();
        return  R.ok(examService.query(uid));
    }

    @GetMapping("ids")
    public R<List<String>> queryExamIds(){
        Long uid = RequestHolder.get().getUid();
        return  R.ok(examService.queryIds(uid));
    }

    @PutMapping("delete")
    public R<String> deleteExam(@RequestBody List<Long> ids){
        // 删除考试成绩
        examService.delete(ids);
        return R.ok("删除成功");
    }

}
